import java.util.*;

class PrimeNumbers {
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        boolean inFlag = false;
        int n = 0;
        
		//Foolproof of entered data
        while (inFlag == false) {
            System.out.print("Enter your (positive, non-zero) number: ");
            if (in.hasNextInt()) {
                n = in.nextInt();
                if (n > 0) {
					inFlag = true;
				} else {
					System.out.println("Number should be bigger than zero. Please, revise.");
					continue;
				}
            }
			if (inFlag != true) {
                System.out.println("Your input(\""+ in.next() + "\") is incorrect. Please, revise.");
            }
        }    
        
        System.out.println("Your number is: " + n);
        
        //Array of all numbers till given
        int[] allNumbers = new int[n];
        for (int i = 1; i <= n; i++) allNumbers[i-1] = i;
        
        System.out.println("All numbers are: " + Arrays.toString(allNumbers));
        
        //Array that will be filled in with Prime numbers
        int[] primeNumbers = new int[n];
        int pnIndex = 0;
        int count = 0;
        for (int i = 2; i <= n; i++) {
            count = 0;
            for (int j = 0; j <= (n-1); j++) {
                if (allNumbers[i-1] % allNumbers[j] == 0) count++;
            }
            if (count <= 2) {
                primeNumbers[pnIndex] = allNumbers[i-1];
                pnIndex++;
            }
        }
        
        //Humanize primeNumbers array
        int[] primeNumbersHum = new int[pnIndex];
        int i = 0;
        while (primeNumbers[i] != 0) {
            primeNumbersHum[i] = primeNumbers[i];
            i++;
        }
        System.out.println("Prime numbers are: " + Arrays.toString(primeNumbersHum));
        
    }

}